package com.alex.web.controller.api;

import com.alex.web.annotation.ExceptionFeedback;
import com.alex.web.bean.CommonResult;
import com.alex.web.bean.member.MpingtHyxx;
import com.alex.web.service.MpingtHyxxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(value = "api/member", description = "会员接口", position = 5)
//@Controller
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("api/member")
public class MemberApiController {

    @Autowired
    private MpingtHyxxService hyxxService;


    /**
     * 根据手机号和密码查询会员信息
     * @param phone
     * @param loginid
     * @param openid
     * @return
     */
    @ExceptionFeedback(errorMsg = "查询会员失败")
    @ApiOperation(value = "查询会员", notes = "查询会员")
    @RequestMapping(value = "/MemberGet", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult getMember(@RequestParam(value = "phone") String phone,
                                  @RequestParam(value = "loginid") String loginid,
                                  @RequestParam(value = "openid") String openid,
                                  @RequestParam(value = "sjid") Integer sjid)  {

        if ((phone == null && loginid == null && openid == null)
                || (phone.trim().equals("null") && loginid.trim().equals("null") && openid.trim().equals("null"))
                || (phone.trim().equals("") && loginid.trim().equals("") && openid.trim().equals(""))){
            return CommonResult.exceptionResult("会员登录信息不完整，请重新登录。", null);
        }

        MpingtHyxx hyxx = hyxxService.getMember(phone,loginid, openid);
        if(hyxx == null){
            return CommonResult.exceptionResult("会员登录信息不完整，请重新登录。", null);
        }

        System.out.println(hyxx);

        return CommonResult.successResult("成功", hyxx);
    }
}
